/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ivanbiz.perpustakaan;

import com.ivanbiz.generic.GenericDAOImpl;
import java.util.Date;
import java.util.List;
import org.hibernate.Query;

/**
 *
 * @author User
 */
public class PeminjamanBukuDAOImpl extends GenericDAOImpl implements PeminjamanBukuDAO{

    public List loadByKartuPerpusAccountKode(String kode) throws Exception {
        Query query = getSessionFactory().getCurrentSession().createQuery("from PeminjamanBuku p where p.kartuPerpus.kodeAccount=:kode and p.deleteFlag=:deleteFlag");
        query.setString("kode", kode);        
        query.setString("deleteFlag", "N");
        return query.list();
    }

    public List cekBukuKeluar() throws Exception {
        Query query = getSessionFactory().getCurrentSession().createQuery("from PeminjamanBuku p where p.deleteFlag=:deleteFlag");          
        query.setString("deleteFlag", "N");
        return query.list();
    }

    public List cariBukuKeluar(String nama, String flag) throws Exception {
        Query query = getSessionFactory().getCurrentSession().createQuery("from PeminjamanBuku b where b.buku.namaBuku like :nama and b.deleteFlag=:flag");
        query.setParameter("nama", "%" + nama + "%");
        query.setParameter("flag",flag);
        return query.list();    
    }

    public List cariKeterlambatan(Date date) throws Exception {
        Query query = getSessionFactory().getCurrentSession().createQuery("from PeminjamanBuku p where p.tanggalKembali >=:tanggalKembali");  
        query.setParameter("tanggalKembali", date);
        return query.list();
       
    }
    
}
